home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Utilities / AmiBroker / Rexx / Telestock / telestock.rexx < prev   
OS/2 REXX Batch file  |  1996-10-22  |  4KB  |  142 lines

  1. /* ARexx-Program to read Telestock quotings into Amibroker
  2.  * (C) 4'96 by M.Baumeister (baumeister@informatik.rwth-aachen.de)
  3.  * may be used freely by anyone
  4.  * may be distributed with Amibroker
  5.  * may not be sold or otherwise comercialized
  6.  *
  7.  * Several small improvements by Tomasz Janeczko
  8.  * October 22nd, 1996
  9.  * (By the way: Big thanks for this script, Markus !!! )
  10.  */
  11.  
  12. /* Synopsis:
  13.  *
  14.  *   rx telestock.rexx <filename>
  15.  *
  16.  * where <filename> is the name of the file containing the quotings
  17.  *
  18.  * It needs an additional file named 'names' containg the translation table
  19.  * from telestock-symbols to Amibroker names
  20. */
  21.  
  22. OPTIONS RESULTS
  23.  
  24.  
  25. ARG filename
  26.  
  27.  
  28. ADDRESS REXX 
  29.  
  30. /* Open translation file */
  31. OPEN(.Aktiennamen,'names','R')
  32. IF( result>0 ) THEN OPEN(.Aktiennamen,'rexx/telestock/names','R')  
  33.  
  34. /* Open quotes file */
  35. OPEN(.Aktienwerte,filename,'R')
  36. IF( result>0 ) THEN OPEN(.Aktienwerte,'rexx/telestock/'filename,'R')
  37.  
  38. /* read symbols and build an associative map */
  39. longname.=""
  40. DO UNTIL EOF(.Aktiennamen)
  41.   line=READLN(.Aktiennamen)
  42.   PARSE VAR line name kuerzel .
  43.   longname.kuerzel=name
  44. end
  45.  
  46.  
  47. CLOSE(.Aktiennamen)
  48.  
  49. ADDRESS 'AMIBROKER.1' 'REQUEST BODY "Telestock import script|(C)1996 Markus Baumeister|Enhanced by Tomasz Janeczko"'
  50.  
  51. /* read quotes */
  52. DO UNTIL EOF(.Aktienwerte)
  53.   /* skip any rubbisch */
  54.   DO UNTIL EOF(.Aktienwerte)
  55.     line=readln(.Aktienwerte)
  56.     if(index(line,'---------------------')>0) then BREAK 
  57.   end
  58.  
  59.   /* After the '-------' line we know we have to ignore 3 lines */
  60.   DO 3 UNTIL EOF(.Aktienwerte)
  61.     dummy=readln(.Aktienwerte)
  62.   end
  63.  
  64.   /* try to identify EOF (doesn't work really) */
  65.   DO UNTIL EOF(.Aktienwerte)
  66.     line=readln(.Aktienwerte)
  67.     if(length(line)>10) then break
  68.   END
  69.   if EOF(.Aktienwerte) then break
  70.  
  71.   /* parse the line containing the symbol of the stock */
  72.   /* "BAY .f" -> kuerzela="BAY", kuerzelb=".f" */
  73.   PARSE VAR line . 6 kuerzela 10 kuerzelb .
  74.   kuerzela=COMPRESS(kuerzela) 
  75.   kuerzel=kuerzela || kuerzelb
  76.   /* find the Amibroker name */
  77.   name=longname.kuerzel
  78.   if(name="") then
  79.     DO
  80.       say 'Werte der Aktie' kuerzel 'können nicht eingefügt werden, da dieses'
  81.       say 'Kürzel unbekannt ist'
  82.     END
  83.   else
  84.       /* read the supplied qoutings */
  85.       CALL readaktie(name)
  86. END
  87. exit
  88.  
  89. readaktie:
  90.         PROCEDURE
  91.         PARSE ARG name
  92.  
  93.         /* again 3 lines must be ignored */
  94.         DO 3 UNTIL EOF(.Aktienwerte)
  95.           dummy=readln(.Aktienwerte)
  96.         end
  97.         IF EOF(.Aktienwerte) THEN RETURN
  98.  
  99.         say 'Stock' name 'is inserted'
  100.  
  101.         /* add stock if it doesn't exist in the database */
  102.         ADDRESS 'AMIBROKER.1' 'ASK STOCK="'name'"'
  103.         IF( result = 0 ) THEN  ADDRESS 'AMIBROKER.1' 'ADDSTOCK' '"'name'"' 'CONT'
  104.  
  105.         /* read each quoting line */
  106.         DO UNTIL EOF(.Aktienwerte)
  107.           line=readln(.Aktienwerte)
  108.           if(length(line)<10) then BREAK
  109.  
  110.           /* due to problems with the "Save to Text" routine of netscape
  111.            * when saving telestock quotings with 4 pre-comma digits
  112.            * we can't depemd on ' ' between the different quote-entries (i.e.
  113.            * high, low, ...). So we have to parse it by hand using the
  114.            * position.
  115.            * THIS IS DANGEROUS!
  116.            * Any change in netscape or telestock can provoke the need to
  117.            * change these lines
  118.           */
  119.           parse var line . 7 date +10 open1 '.' open2  high1 '.' high2  low1 ,
  120.                 '.' low2  close1 '.' close2 +3 . +9 volume .
  121.           date=substr(date,3) /* remove century */
  122.           /* translate '-' (i.e. not available) to 0 */
  123.           if(~ DATATYPE(volume,NUMERIC)) then volume = 0
  124.           volume=trunc(volume+0.5) /* make volume an integer */
  125.           /* say open1 high1 low1 close1 close2 volume */
  126.           close=close1+close2/1000
  127.           open=open1+open2/1000
  128.           high=high1+high2/1000
  129.           low=low1+low2/1000
  130.           say close
  131.           if(volume>0) then
  132.                   ADDRESS 'AMIBROKER.1' 'ADDQUOTATION' '"'name'"' date 'CLOSE=' || close 'volume='|| volume 'OPEN=' || open 'HIGH='|| high 'LOW='|| low
  133.           else
  134.                   ADDRESS 'AMIBROKER.1' 'ADDQUOTATION' '"'name'"' date 'CLOSE=' || close 'OPEN=' || open 'HIGH='|| high 'LOW='|| low
  135.           if(RC>0) then
  136.           do
  137.             say 'Error with AmiBroker:' RC 
  138.             say 'on quote' date volume close open high low
  139.           end
  140.         end
  141.         return
  142.